local basic_world = Game:addState("basic_world")

function basic_world:enteredState()
	print("entering basic world")
	self.x = 100
	self.y = 100
	self.player:spawn(self.x, self.y)
	self.gravity_objects = {}
	self.gravity_objects[#self.gravity_objects+1] = self.player
	-- world_gravity must be less than half player.jump_velocity
	self.world_gravity = 1000
	self.ground_level = 600

	self.static_objects = {}
	self.static_objects[#self.static_objects+1] = Obstacle:new(700, 500, 128, 32, "platform", 
		self.images.platform_one, {{x = 0, y = 0, width = self.images.platform_one:getWidth(), 
		height = self.images.platform_one:getHeight()}})
	
	self.static_objects[#self.static_objects+1] = Obstacle:new(300, 500, 128, 32, "platform", 
		self.images.platform_one, {{x = 0, y = 0, width = self.images.platform_one:getWidth(), 
		height = self.images.platform_one:getHeight()}})

	self.static_objects[#self.static_objects+1] = Obstacle:new(850, 300, 128, 32, "platform", 
		self.images.platform_one, {{x = 0, y = 0, width = self.images.platform_one:getWidth(), 
		height = self.images.platform_one:getHeight()}})

	self.static_objects[#self.static_objects+1] = Obstacle:new(350, 300, 32, 32, "star_box",
		self.images.star_box, {{x = 0, y = 0, width = self.images.star_box:getWidth(),
		height = self.images.star_box:getHeight()}})

	self.colliders = self.static_objects

	self.camera = Camera:new()
	
	self.camera:newLayer(1, function()
		love.graphics.rectangle("fill", self.player.x-love.window.getWidth()*1.5/2, 
			self.player.y-love.window.getHeight()*1.5/2, love.window.getWidth()*1.5, love.window.getHeight()*1.5 )
		end )
	for i = 1, #self.static_objects do
		self.camera:newLayer(1, self.static_objects[i].draw, self.static_objects[i])
	end
	self.camera:newLayer(1, function()
		love.graphics.setColor(0, 0, 0)
		love.graphics.line(self.player.x-love.window.getWidth()*1.5/2, 600, self.player.x+love.window.getWidth()*1.5/2, 600)
		love.graphics.setColor(255,255,255)
		end)
	self.camera:newLayer(1, self.player.draw, self.player)
	self.camera:newLayer(1, function()
		love.graphics.setColor(0, 0, 0)
		love.graphics.print(tostring(love.timer.getFPS()), self.camera.x_zero+10, self.camera.y_zero+10)
		love.graphics.setColor(255,255,255)
		end)

end

function basic_world:draw()
	
	--love.graphics.print("mindslave", 10, 10)
	--love.graphics.rectangle("fill", 0, 0, love.window.getWidth(), love.window.getHeight() )

	--self.player:draw()
	self.camera:draw_layers()

	
end

function basic_world:update(dt)
	self.player:update(dt)
	self.camera:update(dt, self.player)
	self:update_static_objects(dt)
	self:gravity(dt)
	self:near_colliders()

end

function basic_world:exitedState()
	print("exiting basic world")
end
